<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'

const animationDuration = 3000

export default {
  mixins: [resize],
  props: {
    shuju:{

    },
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '500px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  created(){

  },
  methods: {
    initChart() {

      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
         tooltip: {
                 trigger: 'axis',
                 axisPointer: {            // 坐标轴指示器，坐标轴触发有效
                     type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
                 }
             },
             legend: {
                 data: ['总数','玩家赠送','系统添加']
             },
             grid: {
                 left: '3%',
                 right: '4%',
                 bottom: '3%',
                 containLabel: true
             },
             xAxis: [
                 {
                     type: 'category',
                     data: ['票数', '礼物所值票数', '收益']
                 }
             ],
             yAxis: [
                 {
                     type: 'value'
                 }
             ],
             series: [
                 {
                     barWidth:"20%",
                     name: '总数',
                     type: 'bar',
                     emphasis: {
                         focus: 'series'
                     },
                     itemStyle: {
                         normal: {
                             color: '#fc0065',
                             lineStyle:{
                                 borderWidth:1//设置线条粗细
                             }
                         }
                     },
                     data: this.shuju.zongshu

                 },
                 {
                   barWidth:"20%",
                     name: '玩家赠送',
                     type: 'bar',

                     emphasis: {
                         focus: 'series'
                     },
                     itemStyle: {
                         normal: {
                             color: '#409EFF',
                             lineStyle:{
                                 borderWidth:"20%"//设置线条粗细
                             }
                         }
                     },
                     data: this.shuju.wjzs
                 },
                 {
                   barWidth:"20%",
                     name: '系统添加',
                     type: 'bar',

                     emphasis: {
                         focus: 'series'
                     },
                     itemStyle: {
                         normal: {
                             color: '#909399',
                             lineStyle:{
                                 width:"20%"//设置线条粗细
                             }
                         }
                     },
                     data: this.shuju.xttj
                 }
             ]
      })
    }
  }
}
</script>
